package com.onlinemarket.thrid.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.onlinemarket.thrid.daoimpl.goodsDaoImpl;
import com.onlinemarket.thrid.daoimpl.loginImpl;
import com.onlinemarket.thrid.domain.Goods;

@Controller
@RequestMapping(value = "/login")
public class loginControl {
	@Autowired
	private loginImpl loginimpl;
	@Autowired
	private goodsDaoImpl goodsdaoimpl;

	/**
	 * 正确登录
	 * 
	 * @param username
	 * @param password
	 * @return
	 */
	@RequestMapping(value = "/selectUserByUsername")
	public ModelAndView selectUserByUsername(String username, String password) {
		ModelAndView modelAndView = new ModelAndView();
		boolean islogin = loginimpl.checkUser(username, password);
		List<Goods> allgoods = goodsdaoimpl.getallGoods();
		if (islogin) {
			modelAndView.addObject("allgoods", allgoods);
			modelAndView.setViewName("goods/viewallgoods");
		} else {
			modelAndView.setViewName("register");
		}
		return modelAndView;
	}

	/**
	 * 跳转到注册界面
	 * 
	 * @return
	 */
	@RequestMapping(value = "/register")
	public String toregister() {
		return "register";
	}

}
